﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SettingServer;

namespace SettingServer.Controllers
{
    public class FileController : BaseController
    {

       [HttpPost]
       public JsonResult UploadFiles()
        {
            var files = Request.Form.Files;
           // var value =Request.Form.First(c => c.Key == "Name").Value;//获得表单文本项
            foreach (var file in files)
            {
                var fileName = file.FileName;
                string fileaddress = $@"Upload\"+DateTime.Now.ToString("yyyyMMdd");
                if (!Directory.Exists(fileaddress))
                {
                    Directory.CreateDirectory(fileaddress);
                }
                fileName = fileaddress + $@"\{DateTime.Now.ToString("yyyyMMddHHmmss")+fileName}";
                using (FileStream fs = System.IO.File.Create(fileName))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
            }
            return Json(new { code = 0, Msg = "" });
        }
    }
}
